<?php
/**
 * Created by PhpStorm.
 * User: Agiri
 * Date: 15/10/2014
 * Time: 12:06
 */

/**
 * @property $id int
 * @property $nom int
 * @property $idSousCat int
 * @property $prix double
 * @property $descritpion text
 * @property $image string
 */
class Produit {
    //<editor-fold defaultstate="collapsed" desc="région Champs">

    private $_id = null;
    private $_nom = null;
    private $_prix= null;
    private $_idSousCat = null;
    private $_description = "Pas de descritpion disponible pour ce produit pour l'instant";
    private $_image = "defaultImg.jpg";
    public static $nbInstances;

    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="région Propriétés">

    /**
     * @param $propriete
     * @throws Exception
     * @return mixed
     */
    public function __get($propriete){
        switch ($propriete) {
            case "id" : return $this->_id; break;
            case "nom" : return $this->_nom; break;
            case "prix" : return $this->_prix; break;
            case "idSousCat" : return $this->_idSousCat; break;
            case "description" : return $this->_description; break;
            case "image" : return $this->_image; break;
            default:throw new Exception("propriété '$propriete' inconnue...'");
        }
    }
    /**
     * @param $propriete
     * @param $value
     * @throws Exception
     */
    public function __set($propriete, $value) {
        switch ($propriete) {
            case "id" : $this->_id = $value; break;
            case "nom" : $this->_nom = $value; break;
            case "prix" : $this->_prix = $value; break;
            case "idSousCat" :  $this->_idSousCat = $value; break;
            case "description" :  $this->_description = $value; break;
            case "image" :  $this->_image = $value; break;
            default:throw new Exception("propriété '$propriete' inconnue...'");
        }
    }

    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="région Methodes">
    public function __toString(){
        return $this->nom." ".$this->prix." €";
    }

    public function __destruct(){
        Produit::$nbInstances --;
    }

    public function getNbProduits(){
        return count(ModeleBoutique::getLesProduits());
    }

    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="région Constructeur">

    public function __construct( $nom, $prix,$description, $image, $idSousCat, $id = null)
    { //Utilisation de la méthode MAGIQUE __construct;

        $this->nom = $nom;
        $this->prix = $prix;
        $this->description = $description;
        $this->idSousCat = $idSousCat;
        $this->image = $image;
        if ($id != null){
            $this->id = $id;
        }
    }
    //</editor-fold>

} 